using UnityEngine;
public class MonoSingleton<T> : MonoBehaviour where T : MonoSingleton<T>
{
    protected static T instance;
    private static bool IsInit = false;
    public static T Instance
    {
        get
        {
            if (IsInit)return instance;
            var obj = new GameObject(typeof(T).ToString());
            obj.transform.SetParent(GameObject.Find("Manager").transform);
            instance = obj.AddComponent<T>();
            IsInit = true;
            return instance;
        }
    }
    
    protected virtual void Awake()
    {
        if (instance == null)instance = (T)this;
        IsInit = true;
        DontDestroyOnLoad(transform.root.gameObject);
    }

    public static bool CheckInit()
    {
        return IsInit;
    }
    protected virtual void OnDestroy()
    {
        Reset();
        instance = null;
        IsInit = false;
    }
    public virtual void Reset(){
    } 
}